home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / c / hce.lha / HCE / LibSource / clib / Misc / src / fexec.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-02  |  1.4 KB  |  78 lines

  1. #include    <exec/types.h>
  2. #include    <exec/tasks.h>
  3. #include    <libraries/dosextens.h>
  4.  
  5. typedef struct CommandLineInterface CLI;
  6. typedef struct Process PROC;
  7.  
  8. extern    long LoadSeg(), CurrentDir(), System0();
  9. extern    PROC *FindTask();
  10.  
  11. struct pathlist {
  12.     struct pathlist *next;
  13.     unsigned long dirlock;
  14. };
  15. typedef struct pathlist PATH;
  16.  
  17. long
  18. fexecv(cmd, argv)
  19. char *cmd, *argv[];
  20. {
  21.     register CLI *cli;
  22.     register PATH *path;
  23.     PROC *mytask;
  24.     long lock, rv, seglist;
  25.     char buf[128];
  26.     char arg[512];
  27.     int i;
  28.  
  29.     /*
  30.      * Make sure I'm running from the CLI.
  31.      */
  32.  
  33.     mytask = FindTask(0L);
  34.     if ((cli = (CLI *)((unsigned long)mytask->pr_CLI << 2)) == NULL) {
  35.         return(-1);
  36.     }
  37.  
  38.     /*
  39.      * Search currentdir, "Path", and finally c: for the cmd.
  40.      */
  41.  
  42.     if (seglist = LoadSeg(cmd))
  43.         goto found;
  44.  
  45.     path = (PATH *) cli->cli_CommandDir;
  46.     while (path != NULL) {
  47.         path = (PATH *)((unsigned long)path<<2);
  48.         lock = CurrentDir(path->dirlock);
  49.         seglist = LoadSeg(cmd);
  50.         (void)CurrentDir(lock);
  51.         if (seglist)
  52.             goto found;
  53.         path = path->next;
  54.     }
  55.  
  56.     strcpy(buf, "c:");
  57.     strcat(buf, cmd);
  58.     if (seglist = LoadSeg(buf))
  59.         goto found;
  60.     return(-1);
  61.  
  62. found:
  63.     /*
  64.      * Copy the argv vector to arg. Separate parameters by blanks.
  65.      */
  66.     arg[0] = '\0';
  67.     if ( argv[0] != NULL ){
  68.         for ( i=1; argv[i] != NULL; i++){
  69.             if ( i > 1 )
  70.                 strcat(arg, " ");
  71.             strcat( arg, argv[i] );
  72.         }
  73.     }
  74.     rv = System0(cmd, seglist, arg);
  75.     UnLoadSeg(seglist);
  76.     return rv;
  77. }
  78.